package project.dade.cn.bst.utils;

import android.content.Context;
import android.widget.Toast;

/**
 * 工具类：统一管理Toast显示输出，(程序中所有使用Toast处理)
 */
public class ToastUtil {
    /**
     * 定义静态的显示信息类
     */
    private static Toast toast;

    /**
     * 短时间显示Toast
     *
     * @param context 上下文
     * @param message 自定义显示的字符串
     */
    public static void showShort(Context context, CharSequence message) {
        if (null == toast) {
            toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
            // toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    /**
     * 短时间显示Toast
     *
     * @param context 上下文
     * @param message 资源中获取的字符串(ID)
     */
    public static void showShort(Context context, int message) {
        if (null == toast) {
            toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
            // toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    /**
     * 长时间显示Toast
     *
     * @param context 上下文
     * @param message 自定义显示的字符串
     */
    public static void showLong(Context context, CharSequence message) {
        if (null == toast) {
            toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
            // toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    /**
     * 长时间显示Toast
     *
     * @param context 上下文
     * @param message 资源中获取的字符串(ID)
     */
    public static void showLong(Context context, int message) {
        if (null == toast) {
            toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
            // toast.setGravity(Gravity.CENTER, 0, 0);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    /**
     * 隐藏toast
     *
     * @return void
     * @throws
     * @Title: hideToast
     * @Description: 隐藏toast
     */
    public static void hideToast() {
        if (null != toast) {
            toast.cancel();
        }
    }
}
